package com.example.tranport.client.template;

import com.example.message.JmsMessageWrapper;
import com.example.message.Request;
import com.example.message.RequestType;
import com.example.tranport.client.ClientFactory;

import javax.annotation.Resource;

/****
 * 消息推送模板
 */
public class JmsTemplateImpl implements JmsTemplate {

    @Resource
    private ClientFactory clientFactory;

    /****
     * 发送消息到队列
     * @param queueName
     * @param message
     */
    @Override
    public void sendQueue(String queueName, Object message) {
        Request request = new Request();
        request.setType(RequestType.SEND_QUEUE);
        request.setData(new JmsMessageWrapper(queueName, true, message));
        clientFactory.getClientTransPort().getIoSession().write(request);
    }

    /****
     * 发送主题到消息队列
     * @param topicName
     * @param message
     */
    @Override
    public void sendTopic(String topicName, Object message) {
        Request request = new Request();
        request.setType(RequestType.SEND_TOPIC);
        request.setData(new JmsMessageWrapper(topicName, false, message));
        clientFactory.getClientTransPort().getIoSession().write(request);
    }
}
